<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <style>
        body {
            background-image: url('/images/login-background.png');
            background-repeat: no-repeat;
            background-size: cover;
        }

        input {
            height: 30px;
            width: 200px;
            border-radius: 4px;
            border: 1px solid #ccc;
            outline: none;
            font-size: 20px;
        }

        input:hover {
            border: 2px solid blue;
            border-radius: 4px;
        }

        input:focus {
            border: 2px solid blue;
            border-radius: 4px;
        }

        img {
            width: 500px;
            height: auto;
        }

        .main {
            margin-top: 8%;
            margin-left: 15%;
            display: flex;
        }

        button {
            height: 25px;
            font-size: 15px;
        }

        form {
            margin-left: 130px;
        }

        h2 {
            text-align: center;
            margin-top: 40px;
        }

        .right {
            background-image: url("/images/login-right.png");
            background-repeat: no-repeat;
            background-size: cover;
            width: 547px;

        }

        .login {
            margin-left: 50px;
        }

        a {
            margin-left: 50px;
            color: blue;
            text-decoration: none;
        }

        p {
            margin-top: 40px;
        }

        .error {
            color: red;
        }
    </style>
</head>
<body>
<div class="main">
    <img src="/images/login-left.png" alt="加载中.......">
    <div class="right">
        <h2>登录</h2>
        <form id="loginForm" th:action="@{/login}" method="post">
            <p>
                <button type="button">用户名</button>
                <input type="text" name="username" id="username" />
                <span id="usernameError"></span>
            </p>
            <p>
                <button type="button">密&nbsp;&nbsp;&nbsp;码</button>
                <input type="password" name="password" id="password" />
                <span id="passwordError"></span>
            </p>
            <p><input class="login" type="submit" value="登录"/></p>
            <p><a th:href="@{/toRegister}">未注册？点击此处前往注册</a></p>
        </form>
    </div>
</div>
<script>
    var username = document.getElementById('username');
    var password = document.getElementById('password');
    var loginForm = document.getElementById('loginForm');
    var usernameError = document.getElementById('usernameError');
    var passwordError = document.getElementById('passwordError');
    loginForm.addEventListener('submit', function (event) {
        event.preventDefault();
        usernameError.textContent = '';
        passwordError.textContent = '';
        if (username.value === '') {
            usernameError.textContent = '用户名不能为空';
            usernameError.classList.add('error');
            return;
        }
        if (password.value === '') {
            passwordError.textContent = '密码不能为空';
            passwordError.classList.add('error');
            return;
        }
        this.submit();

    })
</script>
</body>
</html>